package util;

import java.util.List;

import entity.BusiestCluster;

public class Util {

	public static final int DEFAULT_INDEX = 0;

	public static String getWhere(String query) {

		int keyOpenIndex = 0;
		int keyClosedIndex = 0;

		for (int i = 0; i < query.length(); i++) {

			if (query.substring(i, i + 1).equals("{")) {
				keyOpenIndex = i + 1;

			}

			if (query.substring(i, i + 1).equals("}")) {

				keyClosedIndex = i;

			}

		}

		return query.substring(keyOpenIndex, keyClosedIndex);

	}

	public static StringBuilder getWhereOnLines(String where) {

		final char dontParam = '.';
		final char space = ' ';

		StringBuilder whereBuilder = new StringBuilder(where);

		for (int i = 0; i < where.length(); i++) {

			if (i > 0 && new Character(where.charAt(i)).equals(dontParam)
					&& new Character(where.charAt(i - 1)).equals(space)) {

				whereBuilder.insert(i + 1, "\n");

			}

		}

		return whereBuilder;
	}

	public static StringBuilder getWhereNodes(StringBuilder whereFormated) {

		final char space = ' ';

		for (int i = 0; i < whereFormated.length(); i++) {

			if (new Character(whereFormated.charAt(i)).equals(space)) {

				whereFormated.insert(i + 1, "\n");

			}

		}

		// System.out.println(whereFormated);

		return whereFormated;
	}

}
